home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 22 / Cream of the Crop 22.iso / program / eflibpt4.zip / DEMO / DATATYPE / LINKLIST.PAS < prev    next >
Pascal/Delphi Source File  |  1996-08-18  |  3KB  |  70 lines

  1. { Borland Pascal Extended Function Library - EFLIB (C) Johan Larsson, 1996
  2.   Demonstration; linked lists
  3.  
  4.   EFLIB IS PROTECTED BY THE COPYRIGHT LAW AND MAY NOT BE COPIED, SOLD OR
  5.   MANIPULATED. FOR MORE INFORMATION, SEE PROGRAM MANUAL! THIS DEMONSTRAT-
  6.   ION PROGRAM MAY FREELY BE USED AND DISTRIBUTED.                          }
  7.  
  8.  
  9. uses EFLIBDEF, EFLIBINI, EFLIBBAS, EFLIBWIN, EFLIBDAT, EFLIBTXT, EFLIBKBD;
  10.  
  11.  
  12. const ListEntries = 13;
  13.  
  14. var MyWindow : WindowObjectType;
  15.     MyList1,
  16.     MyList2  : LinkedListObjectType;
  17.     Data     : string[60];
  18.     Index    : word;
  19.  
  20.  
  21.  
  22. begin
  23.      with MyWindow do begin
  24.           { Initialize a text window }
  25.           InitializeWindow (1, 1, 80, 25, '', NoBorder, FALSE, FALSE);
  26.           SetTextCoordinates (3, 3, 78, 24);
  27.  
  28.           WriteLn ('@C@@LightGreen:Blue@* Linked lists *');
  29.           WriteLn ('@C@@White:Blue@All data types have many common features. Linked lists are equiped');
  30.           WriteLn ('@C@with specific features like active sorting, binary searching and more.');
  31.           WriteLn ('@Yellow:Blue@'); LineFeed;
  32.  
  33.  
  34.           MyList1.InitializeList (SizeOf(Data),      UnsortedOrder,
  35.                                   { Element size }   { Sort order (none) }
  36.                                   TRUE,              FALSE);
  37.                                   { Faster access }  { Reversed access }
  38.  
  39.           Randomize;
  40.  
  41.           { Generate a linked list containing randomly generated strings }
  42.           for Index := 1 to ListEntries do begin
  43.               Data := StringGeneratedRandomly (Pred(SizeOf(Data)));
  44.               MyList1.Add (Data);
  45.           end;
  46.  
  47.           Index := 0; { Reset counter }
  48.  
  49.           { Do a task for each entry; write all entries on the screen }
  50.           with MyList1.CreateIterator^ do begin { Allocate iterator object }
  51.                repeat
  52.                      Inc (Index);
  53.                      MyWindow.WriteLn ('['+StringNumber(Index, 2, 0)+']     : ' + String(Content^));
  54.                      WalkForward; { Next element }
  55.                until IsEnd;
  56.                Free; { Iterator }
  57.           end;
  58.  
  59.           WriteLn ('@White:Blue@');
  60.           WriteLn ('[Intact]  :  ' + StringBoolean (MyList1.IsIntact));
  61.           WriteLn ('[Errors]  :  ' + StringBoolean (GlobalErrorFlag or GlobalDataError));
  62.  
  63.           { Intercept objects (and dispose all entries from the heap) }
  64.           MyList1.Intercept;
  65.  
  66.           repeat until Keyboard.KeyPressed;
  67.  
  68.           Intercept;
  69.      end;
  70. end.